﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace AcademiaInteligenteData.DAL
{
    class DaoMusica_Playlist : DaoConnection
    {
        public void InserirMusica_Playlist(Musica_Playlist musicaplaylist)
        {
            string insertPlaylist = "ai_sp_inserirMusica_Playlist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", musicaplaylist.id));
            parametros[0].Direction = System.Data.ParameterDirection.InputOutput;
            parametros.Add(new SqlParameter("@musica", musicaplaylist.musica));
            parametros.Add(new SqlParameter("@id_playlist", musicaplaylist.id_playlist));
            
            Executar(insertPlaylist, true, parametros);
            musicaplaylist.id = Convert.ToInt32(parametros[0].Value);
        }
        public void AlterarMusica_Playlist(Musica_Playlist musicaplaylist)
        {
            string alterarMusica_Playlist = "ai_sp_alterarMusica_Playlist";
            List<SqlParameter> parametros = new List<SqlParameter>();

            parametros.Add(new SqlParameter("@id", musicaplaylist.id));
            parametros.Add(new SqlParameter("@musica", musicaplaylist.musica));
            Executar(alterarMusica_Playlist, true, parametros);
        }
        public void ExcluirMusica_Playlist(int id)
        {
            string excluirMusica_Playlist = "ai_sp_excluirMusica_Playlist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", id));
            Executar(excluirMusica_Playlist, true, parametros);
        }
        public Musica_Playlist SelecionarMusica_PlaylistPorID(int id)
        {
            string selecionaMusica_Playlist = "ai_sp_selecionarMusica_PlaylistPorID";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", id));
            DataSet reader = Selecionar(selecionaMusica_Playlist, true, parametros);
            int i = 0;
            Musica_Playlist musicaplaylist = new Musica_Playlist();
            musicaplaylist.Playlist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id_playlist"]);
            musicaplaylist.musica = Convert.ToString(reader.Tables[0].Rows[i]["musica"]);
            musicaplaylist.id = id;
            return musicaplaylist;
        }

        public List<Musica_Playlist> ListarMusica_Playlist()
        {
            string listaMusica_Playlist = "ai_sp_listarMusica_Playlist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            DataSet reader = Selecionar(listaMusica_Playlist, true, parametros);
            List<Musica_Playlist> musicplaylists = new List<Musica_Playlist>();
            for (int i = 0; i < reader.Tables[0].Rows.Count; i++)
            {
                Musica_Playlist musicaplaylist = new Musica_Playlist();
                musicaplaylist.id_playlist = Convert.ToInt32(reader.Tables[0].Rows[i]["id_playlist"]);
                musicaplaylist.musica = Convert.ToString(reader.Tables[0].Rows[i]["musica"]);
                musicaplaylist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id"]);
                musicplaylists.Add(musicaplaylist);
            }
            return musicplaylists;
        }

        internal List<Musica_Playlist> ListarMusica_Playlist(int idPlaylist)
        {
            string listaMusica_Playlist = "ai_sp_listarMusica_Playlist";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id_playlist", idPlaylist));
            DataSet reader = Selecionar(listaMusica_Playlist, true, parametros);
            List<Musica_Playlist> musicplaylists = new List<Musica_Playlist>();
            for (int i = 0; i < reader.Tables[0].Rows.Count; i++)
            {
                Musica_Playlist musicaplaylist = new Musica_Playlist();
                musicaplaylist.id_playlist = Convert.ToInt32(reader.Tables[0].Rows[i]["id_playlist"]);
                musicaplaylist.musica = Convert.ToString(reader.Tables[0].Rows[i]["musica"]);
                musicaplaylist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id"]);
                musicplaylists.Add(musicaplaylist);
            }
            return musicplaylists;
        }

        internal List<Musica_Playlist> SelecionarMusica_PlaylistPorAmbiente(int idAmbiente)
        {
            string selecionaMusica_Playlist = "ai_sp_selecionarMusica_PlaylistPorAmbiente";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id_ambiente", idAmbiente));
            DataSet reader = Selecionar(selecionaMusica_Playlist, true, parametros);
            List<Musica_Playlist> musicPlaylist = new List<Musica_Playlist>();
            for (int i = 0; i < reader.Tables[0].Rows.Count; i++)
            {
                Musica_Playlist musicaplaylist = new Musica_Playlist();
                musicaplaylist.id_ambiente = Convert.ToInt32(reader.Tables[0].Rows[i]["id_ambiente"]);
                musicaplaylist.musica = Convert.ToString(reader.Tables[0].Rows[i]["musica"]);
                musicaplaylist.id = Convert.ToInt32(reader.Tables[0].Rows[i]["id"]);
                musicPlaylist.Add(musicaplaylist);
            }
            return musicPlaylist;
        }

        public void InserirMusica_PlaylistAmbiente(Musica_Playlist musicaplaylist)
        {
            string insertPlaylist = "ai_sp_inserirMusica_PlaylistAmbiente";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", musicaplaylist.id));
            parametros[0].Direction = System.Data.ParameterDirection.InputOutput;
            parametros.Add(new SqlParameter("@musica", musicaplaylist.musica));
            parametros.Add(new SqlParameter("@id_ambiente", musicaplaylist.id_ambiente));

            Executar(insertPlaylist, true, parametros);
            musicaplaylist.id = Convert.ToInt32(parametros[0].Value);
        }
        
        public void AlterarMusica_PlaylistAmbiente(Musica_Playlist musicaplaylist)
        {
            string alterarMusica_Playlist = "ai_sp_alterarMusica_PlaylistAmbiente";
            List<SqlParameter> parametros = new List<SqlParameter>();

            parametros.Add(new SqlParameter("@id", musicaplaylist.id));
            parametros.Add(new SqlParameter("@musica", musicaplaylist.musica));
            Executar(alterarMusica_Playlist, true, parametros);
        }
        
        public Musica_Playlist SelecionarMusica_PlaylistAmbientePorID(int id)
        {
            string selecionaMusica_Playlist = "ai_sp_selecionarMusicaAmbiente_PlaylistPorID";
            List<SqlParameter> parametros = new List<SqlParameter>();
            parametros.Add(new SqlParameter("@id", id));
            DataSet reader = Selecionar(selecionaMusica_Playlist, true, parametros);
            int i = 0;
            Musica_Playlist musicaplaylist = new Musica_Playlist();
            musicaplaylist.id_ambiente = Convert.ToInt32(reader.Tables[0].Rows[i]["id_ambiente"]);
            musicaplaylist.musica = Convert.ToString(reader.Tables[0].Rows[i]["musica"]);
            musicaplaylist.id = id;
            return musicaplaylist;
        }
    }
}
